package com.um.jdy.platform.device.controller;

import com.um.jdy.platform.device.entity.dto.BatteryPageDTO;
import com.um.jdy.platform.device.entity.dto.ImportBatteryParams;
import com.um.jdy.platform.device.entity.dto.ImportPileParams;
import com.um.jdy.platform.device.entity.vo.BatteryErrorVO;
import com.um.jdy.platform.device.entity.vo.BatteryItemVO;
import com.um.jdy.platform.device.entity.vo.PileErrorVO;
import com.um.jdy.platform.device.manger.BatteryManager;
import com.um.springboot.starter.annotation.ApiPermission;
import com.um.springboot.starter.annotation.TokenRequired;
import com.um.springboot.starter.entity.Page;
import com.um.springboot.starter.orm.controller.BasePlusController;
import com.um.springboot.starter.orm.entity.Response;
import com.um.springboot.starter.orm.params.ListDTO;
import com.um.springboot.starter.orm.params.PageDTO;
import com.um.jdy.common.device.service.BatteryService;
import com.um.jdy.common.device.entity.po.Battery;
import com.um.jdy.common.device.entity.dto.BatteryDTO;
import com.um.jdy.common.device.entity.vo.BatteryVO;
import com.um.springboot.starter.orm.params.PageParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 控制器：
 */
@RestController
@RequestMapping("/api/v1/cms/device/battery")
@Api(tags = "设备管理", description = "电池管理")
@ApiPermission("battery")
@TokenRequired
public class BatteryController extends BasePlusController<BatteryManager,BatteryService,Battery,BatteryDTO,BatteryVO, PageDTO, ListDTO> {

    /**
     * 分页查询设电池
     * @param params
     * @return
     */
    @ApiPermission("page")
    @ApiOperation(value = "分页查询电池")
    @PostMapping("/battery_page")
    public Response<Page<BatteryItemVO>> getPage(@RequestBody BatteryPageDTO params){
        PageParams pageParams = params.toPageParams(
                new String[]{"sn","platformMerchantId","status"},
                new String[]{"b.sn","b.platform_merchant_id","b.status"});
        return manager.getPage(pageParams);
    }

    /**
     * 导入excel
     *
     * @param params
     */
    @ApiPermission("import")
    @ApiOperation(value = "导入excel")
    @PostMapping("/import")
    public Response<List<BatteryErrorVO>> importExcel(@RequestBody @Valid ImportBatteryParams params){
        return manager.importExcel(params);
    }
}
